package everyday;

import org.junit.jupiter.api.Test;

import java.util.Stack;

public class T1003 {
    public boolean isValid(String s) {
        Stack<Integer> stack = new Stack<>();
        int len = s.length();
        for (int i = 0; i < len; i++) {
            int ch = s.charAt(i);
            if (ch=='a'){
                stack.push(1);
                continue;
            }
            if (stack.isEmpty())return false;
            int p=stack.pop();
            if (ch=='b'){
                if (p==1){
                    stack.push(2);
                }else {
                    return false;
                }
                continue;
            }
            if (ch=='c'){
                if (p==2){
                    continue;
                }else {
                    return false;
                }
            }
        }
        return stack.isEmpty();
    }
    @Test
    public void test() {
        System.out.println(isValid("aabcbabcc"));

    }
}
